﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace News.Models.Database
{
    public partial class NewsContext : DbContext
    {
        public NewsContext()
        {
        }

        public NewsContext(DbContextOptions<NewsContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<NewsPost> NewsPosts { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=News;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Category>(entity =>
            {
                entity.HasKey(e => e.CateId)
                    .HasName("PK__Category__297787E69CCF59A8");

                entity.ToTable("Category");

                entity.Property(e => e.CateId)
                    .ValueGeneratedNever()
                    .HasColumnName("Cate_ID");

                entity.Property(e => e.CateName)
                    .IsRequired()
                    .HasMaxLength(255)
                    .HasColumnName("Cate_Name");
            });

            modelBuilder.Entity<NewsPost>(entity =>
            {
                entity.HasKey(e => e.NewsPId)
                    .HasName("PK__News_Pos__133745C8CCD79742");

                entity.ToTable("News_Post");

                entity.Property(e => e.NewsPId).HasColumnName("NewsP_ID");

                entity.Property(e => e.CateId).HasColumnName("Cate_ID");

                entity.Property(e => e.Content).HasColumnType("text");

                entity.Property(e => e.NewsAdd)
                    .IsRequired()
                    .HasMaxLength(255)
                    .HasColumnName("News_add");

                entity.Property(e => e.NewsTime)
                    .HasColumnType("datetime")
                    .HasColumnName("News_time")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Photo).HasMaxLength(255);

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasMaxLength(255);

                entity.HasOne(d => d.Cate)
                    .WithMany(p => p.NewsPosts)
                    .HasForeignKey(d => d.CateId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK__News_Post__Cate___276EDEB3");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
